from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-04 14:02:28.502914
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 04, Jun, 2022
Time: 14:02:33
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5016
Nobs: 677.000 HQIC: -49.8696
Log likelihood: 8403.99 FPE: 1.74148e-22
AIC: -50.1022 Det(Omega_mle): 1.52618e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.306187 0.059293 5.164 0.000
L1.Burgenland 0.105509 0.038426 2.746 0.006
L1.Kärnten -0.109128 0.020229 -5.395 0.000
L1.Niederösterreich 0.198777 0.080000 2.485 0.013
L1.Oberösterreich 0.122759 0.079033 1.553 0.120
L1.Salzburg 0.255605 0.040917 6.247 0.000
L1.Steiermark 0.046651 0.053605 0.870 0.384
L1.Tirol 0.105301 0.043398 2.426 0.015
L1.Vorarlberg -0.060966 0.038196 -1.596 0.110
L1.Wien 0.034019 0.070075 0.485 0.627
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.041898 0.125788 0.333 0.739
L1.Burgenland -0.033117 0.081521 -0.406 0.685
L1.Kärnten 0.039966 0.042915 0.931 0.352
L1.Niederösterreich -0.185375 0.169718 -1.092 0.275
L1.Oberösterreich 0.442973 0.167666 2.642 0.008
L1.Salzburg 0.285555 0.086804 3.290 0.001
L1.Steiermark 0.108927 0.113721 0.958 0.338
L1.Tirol 0.315303 0.092069 3.425 0.001
L1.Vorarlberg 0.025054 0.081032 0.309 0.757
L1.Wien -0.033582 0.148663 -0.226 0.821
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187589 0.030478 6.155 0.000
L1.Burgenland 0.088139 0.019752 4.462 0.000
L1.Kärnten -0.007544 0.010398 -0.726 0.468
L1.Niederösterreich 0.256154 0.041121 6.229 0.000
L1.Oberösterreich 0.147995 0.040624 3.643 0.000
L1.Salzburg 0.045143 0.021032 2.146 0.032
L1.Steiermark 0.025390 0.027554 0.921 0.357
L1.Tirol 0.086037 0.022308 3.857 0.000
L1.Vorarlberg 0.052824 0.019634 2.690 0.007
L1.Wien 0.119388 0.036020 3.314 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109747 0.030668 3.579 0.000
L1.Burgenland 0.043548 0.019875 2.191 0.028
L1.Kärnten -0.013719 0.010463 -1.311 0.190
L1.Niederösterreich 0.183072 0.041378 4.424 0.000
L1.Oberösterreich 0.321067 0.040878 7.854 0.000
L1.Salzburg 0.103171 0.021163 4.875 0.000
L1.Steiermark 0.110138 0.027726 3.972 0.000
L1.Tirol 0.098630 0.022447 4.394 0.000
L1.Vorarlberg 0.062350 0.019756 3.156 0.002
L1.Wien -0.018890 0.036245 -0.521 0.602
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122522 0.056648 2.163 0.031
L1.Burgenland -0.046513 0.036712 -1.267 0.205
L1.Kärnten -0.045917 0.019326 -2.376 0.018
L1.Niederösterreich 0.145295 0.076431 1.901 0.057
L1.Oberösterreich 0.153689 0.075507 2.035 0.042
L1.Salzburg 0.283016 0.039091 7.240 0.000
L1.Steiermark 0.054022 0.051213 1.055 0.291
L1.Tirol 0.166365 0.041462 4.012 0.000
L1.Vorarlberg 0.095074 0.036492 2.605 0.009
L1.Wien 0.074803 0.066949 1.117 0.264
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060840 0.044741 1.360 0.174
L1.Burgenland 0.030054 0.028996 1.037 0.300
L1.Kärnten 0.051680 0.015264 3.386 0.001
L1.Niederösterreich 0.203191 0.060366 3.366 0.001
L1.Oberösterreich 0.312686 0.059636 5.243 0.000
L1.Salzburg 0.042617 0.030875 1.380 0.167
L1.Steiermark 0.010067 0.040449 0.249 0.803
L1.Tirol 0.133030 0.032747 4.062 0.000
L1.Vorarlberg 0.067234 0.028822 2.333 0.020
L1.Wien 0.089180 0.052877 1.687 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169303 0.053529 3.163 0.002
L1.Burgenland 0.005600 0.034691 0.161 0.872
L1.Kärnten -0.064998 0.018262 -3.559 0.000
L1.Niederösterreich -0.092809 0.072223 -1.285 0.199
L1.Oberösterreich 0.196599 0.071349 2.755 0.006
L1.Salzburg 0.056072 0.036939 1.518 0.129
L1.Steiermark 0.239511 0.048393 4.949 0.000
L1.Tirol 0.503351 0.039179 12.847 0.000
L1.Vorarlberg 0.061122 0.034483 1.773 0.076
L1.Wien -0.071410 0.063263 -1.129 0.259
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153578 0.059775 2.569 0.010
L1.Burgenland 0.000404 0.038739 0.010 0.992
L1.Kärnten 0.060880 0.020393 2.985 0.003
L1.Niederösterreich 0.187019 0.080651 2.319 0.020
L1.Oberösterreich -0.072905 0.079676 -0.915 0.360
L1.Salzburg 0.210461 0.041250 5.102 0.000
L1.Steiermark 0.133603 0.054041 2.472 0.013
L1.Tirol 0.073320 0.043752 1.676 0.094
L1.Vorarlberg 0.143884 0.038507 3.737 0.000
L1.Wien 0.111797 0.070646 1.583 0.114
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.375217 0.035170 10.669 0.000
L1.Burgenland -0.002394 0.022793 -0.105 0.916
L1.Kärnten -0.022117 0.011999 -1.843 0.065
L1.Niederösterreich 0.214133 0.047453 4.512 0.000
L1.Oberösterreich 0.220978 0.046880 4.714 0.000
L1.Salzburg 0.041263 0.024270 1.700 0.089
L1.Steiermark -0.015552 0.031796 -0.489 0.625
L1.Tirol 0.097801 0.025743 3.799 0.000
L1.Vorarlberg 0.056295 0.022657 2.485 0.013
L1.Wien 0.036244 0.041566 0.872 0.383
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037442 0.123157 0.181330 0.145024 0.104671 0.087204 0.040977 0.214013
Kärnten 0.037442 1.000000 -0.018196 0.134051 0.053127 0.092122 0.441028 -0.058740 0.094645
Niederösterreich 0.123157 -0.018196 1.000000 0.328942 0.134256 0.286773 0.083082 0.169477 0.306254
Oberösterreich 0.181330 0.134051 0.328942 1.000000 0.223077 0.313583 0.172959 0.159502 0.259588
Salzburg 0.145024 0.053127 0.134256 0.223077 1.000000 0.133267 0.103144 0.120803 0.134632
Steiermark 0.104671 0.092122 0.286773 0.313583 0.133267 1.000000 0.144171 0.124056 0.058719
Tirol 0.087204 0.441028 0.083082 0.172959 0.103144 0.144171 1.000000 0.079377 0.153784
Vorarlberg 0.040977 -0.058740 0.169477 0.159502 0.120803 0.124056 0.079377 1.000000 0.017663
Wien 0.214013 0.094645 0.306254 0.259588 0.134632 0.058719 0.153784 0.017663 1.000000